
public class Student {
    public String name;
    public int age;
    public static String classes;
    public static String owner = "wx";

    //构造方法
    public Student(String name, int age) {
        System.out.println("构造方法");
        this.name = name;
        this.age = age;
    }
    public void setStudent(String name, int age) {
        this.name = name;
        this.age = age;
    }
    //
    public void print() {
        System.out.println(this.name + " " + this.age+Student.classes);
    }

    {
        System.out.println("实例代码块");
    }
    static {
        System.out.println("静态代码块");
    }

    public static void func(){//静态方法
        //this.name;
        Student.classes = "--xiaohei";//不初始化为默认值null
        //
    }
    public static String getOwner() {
        return owner;
    }

    public static void main(String[] args) {
        //当创建一个新的对象时，调用构造函数
        //同时调用了实例化代码块
        Student student = new Student("aaa",12);
        //当还没有创建对象时，就加载了静态代码块
        System.out.println("=============");
        Student student1 = new Student("bbb",11);
        //再次初始化时不再调用静态代码块
        //只调用一次
    }
    public static void main1(String[] args) {
        Student student1 = new Student("fengxi",2);
        student1.print();
        System.out.println(Student.getOwner());
    }
}
